package com.global.college.adapter;

import android.content.Intent;
import android.view.View;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.global.college.R;
import com.global.college.data.net.HomeGoodListBean;
import com.global.college.ui.activity.CourseDetailActivity;
import com.global.college.utils.LogUtils;
import com.global.college.views.RoundCornerImageview;

/**
 * 课程
 */
public class CourseAdapter extends BaseQuickAdapter<HomeGoodListBean.GoodListBean, BaseViewHolder> {

    public CourseAdapter() {
        super(R.layout.item_course);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeGoodListBean.GoodListBean bean) {
        if (bean.getClassModel() == null) {
            LogUtils.i("未获取到课程信息");
            return;
        }
        View lineView = helper.getView(R.id.view_line);
        if (helper.getAdapterPosition() == (getData().size() - 1)) {
            lineView.setVisibility(View.GONE);
        } else {
            lineView.setVisibility(View.VISIBLE);
        }
        helper.setText(R.id.tv_class_name, bean.getGoodName());
        if (bean.getClassModel().getClassState() == 0) {
            helper.setText(R.id.tv_class_state, "更新中");
            helper.setTextColor(R.id.tv_class_state,mContext.getResources().getColor(R.color.color_red));
            helper.getView(R.id.tv_class_state).setBackground(mContext.getDrawable(R.drawable.border_red_radius_8));
        } else {
            helper.setText(R.id.tv_class_state, "已完结");
            helper.setTextColor(R.id.tv_class_state,mContext.getResources().getColor(R.color.white));
            helper.getView(R.id.tv_class_state).setBackground(mContext.getDrawable(R.drawable.shape_red_radius_8));
        }
        helper.setText(R.id.tv_class_hour, bean.getClassModel().getClassNum() + "课时");
        helper.setText(R.id.tv_class_time, bean.getClassModel().getClassDuration() + "分钟");
        helper.setText(R.id.tv_tag_class,bean.getClassModel().getClassSubjectTagStr());
        helper.setText(R.id.tv_tag_level,getLevelStr(bean.getClassModel().getClassLevel()));
        RoundCornerImageview iv = helper.getView(R.id.riv_lesson_pic);
        Glide.with(mContext).load(bean.getClassModel().getClassCover()).into(iv);
        helper.itemView.setOnClickListener(v -> mContext.startActivity(new Intent(mContext, CourseDetailActivity.class)
                .putExtra("classId", bean.getClassModel().getClassId())
                .putExtra("goodId", bean.getGoodId())));
    }

    private String getLevelStr(int level){
        switch (level){
            case 1:
                return "初级";
            case 2:
                return "中级";
            case 3:
                return "高级";
            default:
                return "中级";
        }
    }

}
